﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MsTestUtilities.SolutionAnalysis;
using System.Xml.Linq;

namespace MsTestUtilitiesTests.SolutionAnalysisTests.BuildConfigurationTests
{
    [TestClass]
    public class ParseBuildConfigurationTests
    {
        private const string xml = @"<PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>";

        private BuildConfiguration _buildConfiguration;

        [TestInitialize]
        public void Setup()
        {
            var element = XElement.Parse(xml);
            var propertyGroup = new PropertyGroup(element);
            _buildConfiguration = BuildConfiguration.FromPropertyGroup(null, propertyGroup);            
        }

        [TestMethod]
        public void Name()
        {
            Assert.AreEqual("Debug|AnyCPU", _buildConfiguration.Name);
        }

        [TestMethod]
        public void Platform()
        {
            Assert.AreEqual("AnyCPU", _buildConfiguration.Platform);
        }

        [TestMethod]
        public void Configuration()
        {
            Assert.AreEqual("Debug", _buildConfiguration.Configuration);
        }

        [TestMethod]
        public void ParseDebugSymbols()
        {
            Assert.IsTrue(_buildConfiguration.DebugSymbols);
        }

        [TestMethod]
        public void TreatWarningsAsErrors()
        {
            Assert.IsFalse(_buildConfiguration.TreatWarningsAsErrors);
        }

        [TestMethod]
        public void DebugType()
        {
            Assert.IsFalse(_buildConfiguration.Optimize);
        }

        [TestMethod]
        public void OutputPath()
        {
            Assert.AreEqual(@"bin\Debug\", _buildConfiguration.OutputPath);
        }

        [TestMethod]
        public void WarningLevel()
        {
            Assert.AreEqual(4, _buildConfiguration.WarningLevel);
        }        
    }
}
